-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace isparta with babel-plugin-istanbul #402
Conversation
@@ -7,7 +7,7 @@ | |||
"scripts": { | |||
"dev": "node build/dev-server.js", | |||
"build": "node build/build.js"{{#unit}}, | |||
"unit": "karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}}, | |||
"unit": "cross-env NODE_ENV=test karma start test/unit/karma.conf.js --single-run"{{/unit}}{{#e2e}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably best to use BABEL_ENV
Babel will use either of these, but will probably be more clear of the use and cause less side affects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blake-newman Thanks! I didn't know it also worked that way
- Used arrays on the include webpack.base field because it's more flexible - Changed the include path to the src directory - Added cross-env when launching karma. This is necessary for coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use babel-istanbul-loader
There are some issues with the syntax highlighting with plugin eg *.vue
files. The plugin also does not cover vue files correctly, the values are wrong.
Works really nicely for me, looking at the source the loader and plugin do not do much different. As they both use babel-istanbul
. Just how the files get parsed to babel-istanbul
.
Developer experience is key with Vue, so i’d rather go with the most appropriate solution, to enable as much awesomeness as possible.
babel-plugin-istanbul:
babel-istanbul-loader:
@posva @blake-newman What's the status on this? |
@LinusBorg There's another thing that we should use. I'm looking into it 😆 edit: https://github.com/deepsweet/istanbul-instrumenter-loader |
@blake-newman I tested the other lib but it doesn't work well. The babel plugin is the recommended way: https://github.com/istanbuljs/istanbul-lib-instrument |
Yeah I'd agree the best library for maintainability. However the development experience with Vue files is a little raw. Syntax and styling is off. Two solutions: Maybe a quick investigation on the later would be good, as it seems alot of tools seem to use the official version. IMO I think creating a babel-vue-script-parser plugin would be nice to extract html. This would be an agnostic solution to parse Vue file script content. Tools like Ava, Jest, Istanbul ect would really benefit from a plugin like this. I would certainly suggest this approach, as Ava is an amazing testing tool. That has alot of React like testing Utils that we could leverage. Like snapshot testing. |
/cc @posva |
Note this is similar to a piece of.work I did to get stylelint to cover style tags. I could easily create a plugin to mimic this for script tags with babel. |
@blake-newman @posva I think Blake's approach would be nice - but would take some time, right? Could we add the babel-plugin for instanbul for now with this PR, and work on the 'babel-vue-script-parser' idea after that? |
Yeah certainly |
@LinusBorg @blake-newman LGTM! |
I know this is closed but I'm pulling my hair out trying to find a solution to what I hope is a related issue. We are building a Vue application using the vue-cli Webpack template. The only change we made was to opt for using Ava for unit testing along with istanbul/nyc as the reporter/coverage tool. Our tests pass, the .vue files show up in the nyc report result but the line numbers are off. By that I mean that nyc is pointing to lines 700, 706, etc. as uncovered but the .vue component being tested only has 400 lines in it. I've been hearing about making sure I have sourceMap: true in my nyc package.json config but I tried setting that and a few other things. Nothing seems to work. So my overall question is: Why is nyc pointing to line numbers that don't exist when I'm testing a .vue component file with ES6 code (and not transpiled files)? If nyc is somehow looking at some transpiled version of my .vue file, how do I map it back (with the correct line numbers) to my .vue component file? |
@aasheer Please see the new recipe for ava.js and vue, this should help. https://github.com/avajs/ava/blob/master/docs/recipes/vue.md |
@blake-newman, thanks for the response. yeah a couple of people suggested your recipe. I have the following in my package.json:
I have the following in my setup.js file:
|
(Sidenote: use 3 backticks oto format blocks of code. I edited your comment accordingly.) |
Looks to me that the issue resides in the order of the helpers for Ava perhaps. Maybe change the setup helper to run last. I would need a reproduction if possible to help further.
|
@blake-newman , I really appreciate the help. Still no luck with your suggestion above, but if it helps at all, here is the default Vue-Cli webpack boilerplate .babelrc file code:
So that's the last piece. I'm assuming |
@blake-newman, I think I finally got it to work! Although I'm not sure why. The only thing I can definitely put my finger on is that if I put
I have to look into all the stuff for babel config but I got some of the config above from the official Ava code-coverage recipe. That being said, I still have to define it in package.json and not in .babelrc Now however, nyc returns actual line numbers that map to my .vue file. If you feel there is anything to add, that I might not be considering, please let me know. Again, thanks for your efforts and the helpful information. |
Some attention points:
cross-env
when launching karma.NODE_ENV=test
is necessary for coverage